<html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css">
dt {
  font-style: italic;
  margin-top: 15px;
  margin-bottom: 3px;
  margin-left: 0px;
  border-bottom: 1px dotted black;
}
dd {
  margin-left: 10px;
}
table {
  border-collapse:collapse;
  border: 1px solid black;
  margin-top: 7px;
}
th {
  border: 1px solid black;
  padding: 3 7 3 7;
}
td {
  border: 1px solid black;
  padding: 3 7 3 7;
}
</style></head><body><p><a name="putstatic"></a><b>putstatic</b> :
  set value of static field : <a href="opcodes.html">index</a> : <a href="http://asm.objectweb.org/asm40/javadoc/user/org/objectweb/asm/MethodVisitor.html#visitFieldInsn(int,%20java.lang.String,%20java.lang.String,%20java.lang.String)">visitFieldInsn()</a></p><dl><dt>Description</dt><dd>putstatic sets the value of the static field (also known as a
class field) identified by &lt;field-spec&gt; to the single or double word
value on the operand stack. For example, when you write the Java expression:<br></br><pre>
    java.lang.System.out = myStream;
</pre>
this
generates a call to getstatic like:<br></br><pre>
    aload_1    ; push object reference in local variable 1 (i.e. myStream) onto stack
               ; now use putstatic to assign it to System.out
    putstatic java/lang/System/out Ljava/io/PrintStream;
</pre>
In
Jasmin, putstatic takes two parameters, &lt;field-spec&gt; and
&lt;descriptor&gt;. &lt;field-spec&gt; provides <i xmlns="">classname</i>, the name of
the class that defines the static field, as well <i xmlns="">fieldname</i>, as the name
of the field. In the example above, the &lt;field-spec&gt; is
"java/lang/System/out", indicating that the <i xmlns="">classname</i> is
"java/lang/System" and the <i xmlns="">fieldname</i> is "out".  &lt;descriptor&gt;
indicates the type of data held in the field, and is a standard Java type
descriptor (see Chapter 4). In the example above, &lt;descriptor&gt; is
"Ljava/io/PrintStream;", i.e. an instance of the PrintStream class.<br></br>putstatic first resolves <i xmlns="">classname</i> into a Java class. Then it
locates the <i xmlns="">fieldname</i> in that class, determining the <i xmlns="">width</i> of the
field (in bytes) and its <i xmlns="">offset</i> (in bytes) from the base of the class's
static data. The type of the field must match &lt;descriptor&gt;. See Chapter 7
for more on how fields are resolved<br></br>To set the value of the field, putstatic pops either a 4-byte or
8-byte quantity off the stack (depending on the field descriptor), and
truncates it to be <i xmlns="">wodth</i> bytes long. Then it sets the bytes starting at
<i xmlns="">offset</i> and extending for <i xmlns="">width</i> bytes in the class's static data
to the new value.</dd><dt>Notes</dt><dd>Fields cannot be overriden, although they can be 'shadowed'. For
example, with the two classes:<br></br><pre>
    class A { static int X; }
and
    class B extends A { static int X; }
</pre>
then
the runtime system will allocate storage for both the static field "A/X" and
the static field "B/X". Which field is accessed is determined by the class name
given in &lt;field-spec&gt;.</dd><dt>See also</dt><dd><a href="ref-putfield.html">putfield</a> <a href="ref-.html"></a> <a href="ref-getfield.html">getfield</a> <a href="ref-.html"></a> <a href="ref-getstatic.html">getstatic</a> </dd><dt>Stack</dt><dd><table xmlns="">
<tr>
<td>
<b>Before </b>
</td>
<td><b>After</b></td></tr>
<tr>
<td>value</td>
<td>...</td></tr>
<tr>
<td>...</td>
<td>...</td></tr>
</table></dd><dt>Bytecode</dt><dd><table xmlns="">
<tr>
<td>
<b> Type </b>
</td>
<td><b>Description</b></td></tr>
<tr>
<td>
u1 
</td>
<td>putstatic
opcode = 0xB3 (179)
</td></tr>
<tr>
<td>
u2 
</td>
<td>index</td></tr>
</table></dd></dl></body></html>